<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm"  :inline="true" v-show="showSearch">
      <el-form-item prop="type">
        <el-select v-model="queryParams.type" style="width: 120px" @keyup.enter.native="handleQuery" @change="changeType">
          <el-option v-for="(dict, index) in fileorupTypeOption" :key="index" :label="dict.label"
                     :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item prop="keyword">
        <el-input v-model="queryParams.keyword" placeholder="请输入关键字" clearable style="width: 240px" maxlength="30"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button style="margin-left: 20px" type="primary" icon="el-icon-search"  @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8" ref="refbut">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList" :height="tableHeight">
      <el-table-column label="序号" type="index" :index="table_index" width="55" align="center" prop="id"/>
      <el-table-column label="文件标题" prop="title" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="保管期限" prop="bgqx" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="年度" prop="nd" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="密级" prop="mj" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="归档司局" prop="gdsj" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="归档处室" prop="gdcs" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="上架位置" prop="position" align="center" :show-overflow-tooltip="true" />
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />


  </div>
</template>

<script>
import estimateTableHeight from '@/mixins/estimateTableHeight'
import {getFileList} from "@/api/archive/warehouseManagement/fileLocation";
export default {
  name: "index",
  mixins: [estimateTableHeight], // 混入方法
  archive_Dicts: ['BGQX', 'MJ'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 查询参数
      queryParams: {
        pageNum:1,
        pageSize:10,
        type: '0',
        keyword: undefined,
      },
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      dataList: [],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      fileorupTypeOption: [
        {value: '0',label: '文件层'},
        {value: '1',label: '案卷层'}
      ],
    }
  },
  created() {
    this.getList()
  },
  methods: {
    table_index(index){
      return (this.queryParams.pageNum-1) * this.queryParams.pageSize + index + 1;
    },
    changeType() {
      this.handleQuery()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 获取表格数据
    getList() {
      this.loading = true
      getFileList(this.queryParams).then(response=>{
        this.dataList = response.rows
        for (let i = 0; i < response.rows.length; i++) {
          // 渲染表格数据
          for (let j = 0; j < this.dict.type.BGQX.length; j++) {
            if(response.rows[i].bgqx == this.dict.type.BGQX[j].value){
              this.dataList[i].bgqx = this.dict.type.BGQX[j].label
            }
          }
          for (let j = 0; j < this.dict.type.MJ.length; j++) {
            if(response.rows[i].mj == this.dict.type.MJ[j].value){
              this.dataList[i].mj = this.dict.type.MJ[j].label
            }
          }
        }
        this.total = response.total
        this.loading = false
      })
    }
  }
}
</script>

<style scoped>

</style>
